package com.zzptc.myapp1030;

import androidx.appcompat.app.AppCompatActivity;

import android.icu.text.UnicodeSetSpanner;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    GridView gridView;//全局变量自动化
    int[] tupian = new int[6];
    int[] pics = {R.mipmap.lanqiu, R.mipmap.xinxi, R.mipmap.zhaoxiang, R.mipmap.dijia,
            R.mipmap.leiou, R.mipmap.maikesi,R.mipmap.xiede,R.mipmap.gaiya,R.mipmap.daina};

    String[] titles = {"篮球", "信息", "照相", "迪迦", "雷欧", "麦克斯","捷德","盖亚","戴拿"};
    List<Map<String,Object>> list;

    //List<String>list1;


    //  String[]S=new String[9];


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gridView = findViewById(R.id.G_menu);//实例化控件

        //第一步；布局(大 小)，实例化控件

        //第二步；准备数据
        // tupian[0]=R.mipmap.lanqiu;
        //tupian[1]=R.mipmap.xinxi;
        //tupian[2]=R.mipmap.zhaoxiang;
        //tupian[3]=R.mipmap.dijia;
        //tupian[4]=R.mipmap.leiou;
        //tupian[5]=R.mipmap.maikesi;
        list = new ArrayList<>();
        getData();

        String[] from = {"biaot", "icon"};
        int[] to = {R.id.tv_title, R.id.iv_pic};
        SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, list, R.layout.item, from, to);
        gridView.setAdapter(simpleAdapter);


    }

        private void getData(){

        for (int i=0;i<titles.length;i++){
            Map<String, Object> map = new HashMap<>();
            map.put("biaot",titles[i]);
            map.put("icon",pics[i]);
            //添加到集合中
            list.add(map);




        }
        //Map<String, Object> map = new HashMap<>();
        //map.put("biaot",titles[0]);
       // map.put("icon",pics[0]);

        /*Map<String,Object>map1=new HashMap<>();
        map1.put("biaot",titles[1]);
        map1.put("icon",pics[1]);

        list = new ArrayList<>();
        Map<String, Object> map2 = new HashMap<>();
        map.put("biaot",titles[1]);
        map.put("icon",pics[1]);

        Map<String,Object>map3=new HashMap<>();
        map1.put("biaot",titles[2]);
        map1.put("icon",pics[2]);*/



       // list.add(map);
       // list.add(map1);
        //list.add(map2);
        //list.add(map3);


    }
}

